package com.cx.bank.controller;

import com.cx.bank.mapper.UserMapper;
import com.cx.bank.pojo.Log;
import com.cx.bank.pojo.UserBean;
import com.cx.bank.service.LogService;
import com.cx.bank.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LogController {
    @Autowired
    LogService logService;
    @Autowired
    UserMapper userMapper;
    @RequestMapping("/user/log")
    public String findLogs(Model model){
        List<Log> logs = logService.findLogs();
        model.addAttribute("logs",logs);
        return "/user/log";
    }
    @RequestMapping("/user/logByUserId")
    public String logByUserId(Model model, HttpSession session){
        UserBean userBean = (UserBean) session.getAttribute("currentUser");
        List<Log> userLogs = logService.selectLogByUserId(userMapper.findUserIdByUserName(userBean.getUserName()));
        model.addAttribute("logs",userLogs);
        return "/user/log";
    }
}
